package ferp.android.dialogs;

import android.content.Context;
import ferp.android.R;
import ferp.core.game.Settings;
import ferp.core.log.Log;

/**
 * User: igorgok
 * Date: 17/06/2014 15:49
 */
public class LoadingDialog
{
  public static void show(Context context, int text)
  {
    show2(context, context.getString(text));
  }

  public static void showDeck(Context context, String deck)
  {
    show2(context, context.getString(R.string.dialog_deck_loading,
                                     deck.equals(Settings.DECK_STANDARD) ? context.getString(R.string.settings_deck_standard) : deck));
  }

  public static void dismiss()
  {
    if (progress != null)
    {
      try
      {
        progress.dismiss();
      }
      catch (IllegalArgumentException e)
      {
        /* do nothing */
      }

      progress = null;

      Log.debug(Log.TAG, "loading dialog dismissed");
    }
    else
      Log.debug(Log.TAG, "loading dialog is null");
  }

  private static void show2(Context context, String text)
  {
    boolean create = progress == null;

    if (create)
      progress = new ProgressDialog(context);

    progress.set(R.string.please_wait, text);

    //Log.debug(Log.TAG, "showing in loading dialog - " + text);

    if (create)
      progress.show();
  }

  private static ProgressDialog progress;
}
